import { API } from './API';
import TableMgr from '../manager/TableMgr';

export class HeroView {
  private _head: string;
  private _mod: number;
  private _img: string;

  private _att_sound: Array<number>;
  private _hurt_sound: Array<number>;
  private _died_sound: Array<number>;
  public constructor() {
    this._head = '';
    this._img = '';
    this._mod = NaN;
    this._att_sound = new Array<number>();
    this._hurt_sound = new Array<number>();
    this._died_sound = new Array<number>();
  }
  public set head(value: string) {
    this._head = value;
  }
  public set mod(value: number) {
    this._mod = value;
    var conf: res_dragonNode = TableMgr.inst.getDragonConfigById(this._mod);
    // this._img = conf.img;
    // this._att_sound = conf.att_sound;
    // this._hurt_sound = conf.hurt_sound;
    // this._died_sound = conf.died_sound;
    this.head = conf.head;
  }
  public get img(): string {
    return this._img;
  }
  public get attSound(): number {
    if (this._att_sound.length == 0) return 0;
    return this._att_sound[Math.floor(Math.random() * this._att_sound.length)];
  }
  public get hurtSound(): number {
    if (this._hurt_sound.length == 0) return 0;
    return this._hurt_sound[Math.floor(Math.random() * this._hurt_sound.length)];
  }
  public get diedSound(): number {
    if (this._died_sound.length == 0) return 0;
    return this._died_sound[Math.floor(Math.random() * this._died_sound.length)];
  }
  public get head(): string {
    return this._head;
  }
  public get mod(): number {
    return this._mod;
  }
  public encode(): any {
    var obj: any = {};

    obj.mod = this._mod;
    return obj;
  }
  public decode(data: any) {
    this._mod = data.mod;
  }
}
